<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layui-form layuimini-form layui-form-pane">
    <div class="layui-form-item">
        <input type="hidden" name="member_code" value="{$memberCode}">
        <label class="layui-form-label required">选择行业</label>
        <div class="layui-input-inline">
            <input type="hidden" name="industry_id" id="industryId" lay-verify="required">
            <input type="hidden" name="industry_title" id="industryTitle" lay-verify="required">
            <input type="hidden" name="industry_imgurl" id="industryImg" lay-verify="required">
            <input type="hidden" name="earnings_level" id="earningsLevel" lay-verify="required">
            <input type="hidden" name="day_rent" id="day_rent" lay-verify="required">
            <input type="text" placeholder="请选择行业" autocomplete="off" readonly class="layui-input" id="industry_id">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">选择生长周期</label>
        <div class="layui-input-inline">
            <input type="hidden" name="growth_cycle" id="growthCycle" lay-verify="required">
            <input type="hidden" name="day_income" id="dayIncome" lay-verify="required">
            <input type="text" placeholder="请先选择行业" autocomplete="off" readonly class="layui-input" id="growth_cycle">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">周期收益</label>
        <div class="layui-input-inline">
            <input type="number" placeholder="请填写周期收益" name="earnings_price" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">购买金额</label>
        <div class="layui-input-inline">
            <input type="number" placeholder="请填写购买金额" name="buy_price" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'tableSelect', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            $ = layui.$;
        /*选择行业*/
        tableSelect.render({
            elem: '#industry_id',
            searchKey: 'title',
            checkedKey: 'id',
            searchPlaceholder: '名称搜索',
            table: {
                url: '/admin/Member/giveBusiness?action=business',
                method: 'post',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data, //解析数据列表
                    };
                },
                cols: [[
                    {type: 'radio'},
                    {field: 'title', title: '名称', sort: true},
                    {field: 'levelTitle', title: '所属等级', sort: true},
                    {field: 'day_rent', title: '每日租金', sort: true},
                ]],
                page: true,
                limits: [15, 20, 25, 30, 50, 100],
                limit: 15
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.title)
                    $('#industryId').val(item.id);
                    $('#industryTitle').val(item.title);
                    $('#earningsLevel').val(item.level);
                    $('#industryImg').val(item.logo);
                    $('#day_rent').val(item.day_rent);
                });
                elem.val(NEWJSON.join(","));
                $('#growth_cycle').val('');
                $('#growthCycle').val('');
                $('#dayIncome').val('');
                /*选择行业周期*/
                tableSelect.render({
                    elem: '#growth_cycle',
                    searchKey: 'title',
                    checkedKey: 'id',
                    searchPlaceholder: '名称搜索',
                    table: {
                        url: '/admin/Member/giveBusiness?action=businessCycle',
                        method: 'post',
                        where:{industryId:$('#industryId').val()},
                        parseData: function (res) { //res 即为原始返回的数据
                            return {
                                "code": res.code, //解析接口状态
                                "msg": res.msg, //解析提示文本
                                "count": res.data.total, //解析数据长度
                                "data": res.data.info, //解析数据列表
                            };
                        },
                        cols: [[
                            {type: 'radio'},
                            {field: 'min_num', title: '最低价值', sort: true},
                            {field: 'day_income', title: '每日收益', sort: true},
                            {field: 'cycle_period', title: '收益周期', sort: true},
                            {field: 'max_num', title: '最高价值', sort: true},
                        ]],
                        page: false,
                        limits: [15, 20, 25, 30, 50, 100],
                        limit: Number.MAX_VALUE
                    },
                    done: function (elems, datas) {
                        layui.each(datas.data, function (index, item) {
                            $('#growth_cycle').val(item.cycle_period);
                            $('#growthCycle').val(item.cycle_period);
                            $('#dayIncome').val(item.day_income);
                        })
                    }
                });
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/admin/Member/giveBusiness?action=ajax',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (res) {
                    if (res.status == true) {
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function () {
                    layer.msg("报错了");
                }
            });

            return false;
        });

    });
</script>
</body>
</html>